package sort.快速排序;


public class QuickSort1 {

    public static void test() {
        int[] arrays = {12,47,39,9,38,49,200,6};
        quickSort(arrays,0,arrays.length-1);
        for (int array : arrays) {
            System.out.println(array);
        }
    }
    public static void quickSort(int[] a, int low, int high) {
        if (low < high) {
            int middle = getMiddle(a,low,high);
            quickSort(a,low,middle - 1);
            quickSort(a,middle + 1,high);
        }
    }
    public static int getMiddle(int[] arrays, int low, int high) {
        int tmp = arrays[low];
        while (low < high) {
            // 先看右边
            while (arrays[high] > tmp && low < high) {
                high--;
            }
            while (arrays[low] < tmp && low < high) {
                low++;
            }
            while (low < high) {
                int a = arrays[low];
                arrays[low] = arrays[high];
                arrays[high] = a;
            }
        }
        arrays[low] = tmp;
        return low;
    }
}
